<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Position, PositionDel, PositionCheckStatus } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "招募中", value: "1" },
        { label: "已关闭", value: "2" },
      ],
      queryData: {
        position_status: "",
        position_name: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    checkStatus(row, type) {
      let str = type == 1 ? "开启" : "关闭";
      ElMessageBox.confirm(`确定${str}选择的岗位吗?`, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = {
          enterprise_position_id: row.enterprise_position_id,
          position_status: type,
        };
        PositionCheckStatus(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的岗位吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const { data } = await PositionDel({
          enterprise_position_id: row.enterprise_position_id,
        });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
    addFn(id) {
      this.$router.push({
        path: "/workListAdd",
        query: { id: id, page: id ? this.queryData.page : undefined },
      });
    },
    detailFn(id) {
      this.$router.push({
        path: "/workListDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    async getData() {
      const { data } = await Position(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>岗位列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.position_name"
                placeholder="请输入岗位职务"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.position_status"
                clearable
                @change="getData"
                placeholder="请选择岗位状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @ok="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="c_enterprise_name"
          show-overflow-tooltip
          width="150"
          label="船东公司"
        >
          <template #default="{ row }">
            {{ row.c_enterprise_name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="watercraft_name"
          show-overflow-tooltip
          label="船舶名称"
        />
        <el-table-column
          prop="position_name"
          show-overflow-tooltip
          label="岗位职务"
        />
        <el-table-column
          width="90"
          prop="zprs"
          show-overflow-tooltip
          label="招聘人数"
        >
          <template #default="{ row }">{{ row.zprs }}（人）</template>
        </el-table-column>
        <el-table-column
          prop="workMoney"
          width="160"
          show-overflow-tooltip
          label="薪资待遇"
        >
          <template #default="{ row }">
            <div v-if="row.start_monry == '0'">面议</div>
            <div v-else>
              {{ row.start_monry }}~{{ row.end_monry }}（{{
                row.unit == 1 ? "元" : "美元"
              }}）
            </div>
          </template>
        </el-table-column>
        <el-table-column width="80" show-overflow-tooltip label="岗位类型">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag type="info" v-if="row.position_type === 2"
                >普通岗位</el-tag
              >
              <el-tag type="danger" v-if="row.position_type === 1"
                >急聘岗位</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column width="80" show-overflow-tooltip label="岗位状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag type="success" v-if="row.position_status === 1"
                >招募中</el-tag
              >
              <el-tag type="danger" v-if="row.position_status === 2"
                >已关闭</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="hygk" show-overflow-tooltip label="换员港口" />
        <el-table-column
          width="80"
          prop="gl_staff"
          show-overflow-tooltip
          label="发布员工"
        >
          <template #default="{ row }">
            {{ row.gl_staff }}
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          width="170"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column prop="Name" width="170" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.enterprise_position_id)"
              >
                详情
              </div>
              <div
                v-if="row.is_auth == 1"
                class="blueText ctrlText"
                @click="addFn(row.enterprise_position_id)"
              >
                编辑
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.position_status === 2 && row.is_auth == 1"
                @click="checkStatus(row, 1)"
              >
                开启
              </div>
              <div
                class="redText ctrlText"
                v-if="row.position_status === 1 && row.is_auth == 1"
                @click="checkStatus(row, 2)"
              >
                关闭
              </div>
              <div
                class="redText ctrlText"
                v-if="row.is_auth == 1 && false"
                @click="deleteFn(row)"
              >
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
